Defining Script Objects
Each script object definition begins with the keywordscript
, followed by an optional variable name, and ends with the keywordend
(orend script
). The statements in between can be any combination of property definitions, handler definitions, and other AppleScript statements.The syntax of a script object definition is
script [ scriptObjectVariable ] [( property | prop ) propertyLabel : initialValue ]... [ handlerDefinition ]... [ statement ]... end [script]wherescriptObjectVariable is a variable identifier. If you include scriptObjectVariable, AppleScript stores the script object in a variable. You can use the variable identifier to refer to the script object elsewhere in the script.
propertyLabel is an identifier for a property. Properties are characteristics that are identified by unique labels. They are similar to instance variables in object-oriented programming.
initialValue is the value that is assigned to the property each time the script object is initialized. Script objects are initialized when the scripts or handlers that contain them are run. initialValue is required in property definitions.
handlerDefinition is a handler for a user-defined or system command. The handlers within a script object definition determine which commands the script object can respond to. Script object definitions can include handlers for userdefined commands (subroutines) or for system or application commands. Handlers in script objects are similar to methods in object-oriented programming. For a detailed description of the syntax of handler definitions, refer to Chapter 8, "Handlers."
statement is any AppleScript statement. Statements other than handler and property definitions are treated as if they were part of a handler definition
for the Run command; they are executed when a script object receives the
Run command.